package pl.diagnoser.server.persistance.map;

import static javax.persistence.GenerationType.IDENTITY;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table(name = "T_SEARCH_RESULT")
public class SearchResult implements Serializable {
	
	private static final long serialVersionUID = 1L;
	private long searchResultId;
	private Timestamp date;
	private Objects objects;
	private Set<SearchResultAttributes> objectAttributes = new HashSet<SearchResultAttributes>(0);
	
	public SearchResult(){}
	public SearchResult(long searchResultId, Timestamp date, Objects objects) {
		super();
		this.searchResultId = searchResultId;
		this.date = date;
		this.objects = objects;
	}
	public SearchResult(Objects objects) {
		super();
		this.objects = objects;
	}
	
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column( name="SEARCH_RESULT_ID", unique = true, nullable = false )
	public long getSearchResultId() {
		return searchResultId;
	}
	public void setSearchResultId(long searchResultId) {
		this.searchResultId = searchResultId;
	}
	
	@Column( name="DATE", unique = false, nullable = true )
	public Timestamp getDate() {
		return date;
	}
	public void setDate(Timestamp date) {
		this.date = date;
	}
	
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="OBJECT_ID")
	public Objects getObjects() {
		return objects;
	}
	public void setObjects(Objects objects) {
		this.objects = objects;
	}
	
	@OneToMany( mappedBy = "searchResult" )
	public Set<SearchResultAttributes> getObjectAttributes() {
		return objectAttributes;
	}
	public void setObjectAttributes(Set<SearchResultAttributes> objectAttributes) {
		this.objectAttributes = objectAttributes;
	}
}